package com.mcflies.aotoPartsManager.util;

import java.util.Properties;

import org.apache.log4j.Logger;

import com.mcflies.aotoPartsManager.dao.CustomerAreaDAO;
import com.mcflies.aotoPartsManager.dao.LeftMenuTreeConfigDAO;

/**
 * AutoPartsDAOFactory.java
 * 
 * @describe：汽车配件管理系统,DAO工厂类
 * @Copyright(c) 2012-2024 Study,mcfly
 * @author mcfly_jun
 */
public class AutoPartsDAOFactory {
	private static LeftMenuTreeConfigDAO leftMenuTreeConfigDAO;
	private static CustomerAreaDAO customerAreaDAO;

	private static Logger log = Logger.getLogger(AutoPartsDAOFactory.class);
	private static Properties pro;
	static {
		try {
			pro = new Properties();
			pro.load(AutoPartsDAOFactory.class.getClassLoader().getResourceAsStream(
					"com/mcflies/aotoPartsManager/util/autoPartsDAOConfig.properties"));

		} catch (Exception e) {
			log.info("在[" + AutoPartsDAOFactory.class.getName() + "]中加载(static代码块)出现：：" + e.getMessage() + "异常");
		}
	}

	/**
	 * 实例化LeftMenuTreeConfigDAO
	 * 
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public synchronized static LeftMenuTreeConfigDAO getLeftMenuTreeConfigDAO() throws Exception {
		if (null == leftMenuTreeConfigDAO) {
			Class cls = Class.forName(pro.getProperty(AutoPartsConstantKey.AUTO_PARTS_LEFT_MENU_TREE_CONFIG_DAO));
			leftMenuTreeConfigDAO = (LeftMenuTreeConfigDAO) cls.newInstance();
		}
		return leftMenuTreeConfigDAO;
	}

	/**
	 * 实例化CustomerAreaDAO
	 * 
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public synchronized static CustomerAreaDAO getCustomerAreaDAO() throws Exception {
		if (null == customerAreaDAO) {
			Class cls = Class.forName(pro.getProperty(AutoPartsConstantKey.AUTO_PARTS_CUSTOMER_AERA_DAO));
			customerAreaDAO = (CustomerAreaDAO) cls.newInstance();
		}
		return customerAreaDAO;
	}
}
